package main

import "fmt"

func arrayDemo() {

	var arr1 [5]int
	arr2 := [3]int{1, 3, 5}
	arr3 := [...]int{2, 4, 6, 8, 10}

	fmt.Println(arr1, arr2, arr3)

	//二维数组
	var grid [4][5]int
	var grid2 [4][5]bool
	fmt.Println(grid)
	fmt.Println(grid2)

	//数组遍历
	//for i := 0; i < len(arr3); i++ {
	//如上可以写成如下，效果相等，i为下标，v为值
	for i, v := range arr3 {
		fmt.Println(arr3[i], v)
	}
	fmt.Println("*******************")
	// 如下验证值传递还是引用传递
	for i, v := range arr3 {
		v++
		fmt.Println(arr3[i], v)
	}

	// 如果只想用值
	for _, v := range arr3 {
		fmt.Println(v)
	}
}

func printArray(arr [5]int) {
	arr[0] = 100
	for i, v := range arr {
		fmt.Println(arr[i], v)
	}

}
func printArrayPointer(arr *[5]int) {
	arr[0] = 100
	for i, v := range arr {
		fmt.Println(arr[i], v)
	}

}

func printArraySlice(arr []int) {
	arr[0] = 100
	for i, v := range arr {
		fmt.Println(arr[i], v)
	}
}

func main() {
	var arr1 [5]int
	arr3 := [...]int{2, 4, 6, 8, 10}
	//printArray(arr3)
	//fmt.Println("***********")
	//fmt.Println(arr3)
	//printArrayPointer(&arr3)
	//fmt.Println(arr3)

	printArraySlice(arr1[:])
	fmt.Println(arr1)
	printArraySlice(arr3[:])
	fmt.Println(arr3)
}
